//
//  DDHotSaleView.m
//  Dingdong
//
//  Created by 程强 on 16/11/14.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDHotSaleView.h"
#import "DDGoodsCollectionCell.h"

@interface DDHotSaleView()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate>
@property (strong, nonatomic) UICollectionView *hotCollection;
@end

static NSString *indentifier = @"GoodsCell";


@implementation DDHotSaleView

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:titleView];
        titleView.backgroundColor = RGBColor(244, 244, 244);
        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.left.equalTo(self);
            make.height.equalTo(@45);
        }];
        
        KKLabel *saleLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"HOT SALE",RGBColor(137, 137, 137),[UIFont systemFontOfSize:15.0],NSTextAlignmentCenter);
        }];
        [titleView addSubview:saleLbl];
        [saleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(titleView);
            make.width.equalTo(@80);
            make.height.equalTo(@30);
        }];
        
        UIView *leftLine = [[UIView alloc]init];
        [titleView addSubview:leftLine];
        leftLine.backgroundColor = RGBColor(215, 215, 215);
        [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(titleView);
            make.left.equalTo(titleView).offset(15);
            make.right.equalTo(saleLbl.mas_left).offset(-10);
            make.height.equalTo(@1);
        }];
        
        UIView *rightLine = [[UIView alloc]init];
        [titleView addSubview:rightLine];
        rightLine.backgroundColor = RGBColor(215, 215, 215);
        [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(titleView);
            make.left.equalTo(saleLbl.mas_right).offset(10);
            make.right.equalTo(titleView).offset(-15);
            make.height.equalTo(@1);
        }];
        
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
        //设置布局方向为垂直流布局
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        CGFloat width = (ScreenWidth-20)/2.0;
        CGFloat height = width+50;
        layout.itemSize = CGSizeMake(width, height);
        
        UICollectionView *collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
        collection.delegate = self;
        collection.dataSource = self;
        [collection registerClass:[DDGoodsCollectionCell class] forCellWithReuseIdentifier:indentifier];
        collection.backgroundColor = [UIColor whiteColor];
        [self addSubview:collection];
        self.hotCollection = collection;
        [_hotCollection mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.top.equalTo(titleView.mas_bottom);
        }];
        _hotCollection.scrollEnabled = NO;
    }
    return self;
}
#pragma mark --- UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DDGoodsCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:indentifier forIndexPath:indexPath];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}
#pragma mark ---- UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat width = (ScreenWidth-20)/2.0;
    CGFloat height = width+50;
    return (CGSize){width,height};
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 5, 5, 5);
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5.f;
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 5.f;
}

@end
